﻿using PeiYue.IRepository.Base;
using PeiYue.IServices.Tms;
using PeiYue.Model;
using PeiYue.Model.Models.Tms;
using PeiYue.Services.BASE;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace PeiYue.Services.Tms
{
    public class RouterShopLogServices: BaseServices<RouterShopLogDao>, IRouterShopLogServices
    {
        IBaseRepository<RouterShopLogDao> _dal;
        IBaseRepository<RouterShopDao> _routerShopDal;
        public RouterShopLogServices(IBaseRepository<RouterShopLogDao> dal, IBaseRepository<RouterShopDao> routerShopDal)
        {
            this._dal = dal;
            base.BaseDal = dal;
            this._routerShopDal = routerShopDal;
        }
        /// <summary>
        /// 保存物流费，更新线路门店日志表，用来统计每日物流费比
        /// </summary>
        /// <param name="routerId">线路id</param>
        /// <param name="feeDate">费用日期</param>
        /// <param name="userId">操作人</param>
        /// <returns></returns>
        public async Task UpdateRouterShopLog(long routerId, DateTime feeDate,long userId)
        {
            int status = (int)CommonEnum.Status.Enable;
            List<RouterShopLogDao> list = new List<RouterShopLogDao>();
            var routerShopList = await _routerShopDal.Query(t => t.router_id == routerId && t.status == status);
            foreach (var routerShopDao in routerShopList)
            {
                RouterShopLogDao routerShopLogDao = new RouterShopLogDao();
                routerShopLogDao.router_id = routerShopDao.router_id;
                routerShopLogDao.customer_id = routerShopDao.customer_id;
                routerShopLogDao.shop_id = routerShopDao.shop_id;
                routerShopLogDao.shop_code = routerShopDao.shop_code;
                routerShopLogDao.log_date = feeDate;
                routerShopLogDao.id = await _dal.GenId();
                list.Add(routerShopLogDao);
            }
            if (list.Count > 0)
                await _dal.Add(list);
        }
    }
}
